class PostsController < ApplicationController
  filter_access_to :all

  def new
  end

  def create
    @post = Post.new(params[:post])
    @forum_thread = ForumThread.find(params[:post][:forum_thread_id])
    @post.user_id = current_user.id
   
    if @forum_thread.locked != true
      if @post.save
        flash[:notice] = "Post created!"
        redirect_to_request_uri
      else
        render 'forum_threads/show'
      end
    else
      flash[:notice] = "This thread is locked. Posting is no " +
      "longer permitted!"    
      redirect_to_request_uri
    end    
    
  end

  def edit
    @post = Post.find(params[:id])
  end

  def update
    @post = Post.find(params[:id])

    if @post.update_attributes(params[:post])
      flash[:notice] = "Post updated!"
      redirect_to @post.forum_thread
    else
      render :edit
    end
  end

  def destroy
    @post = Post.find(params[:id])
    @post.destroy
    flash[:notice] = "Post successfully deleted."
    redirect_to_request_uri
  end

end
